<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" session="false" %><%@
include file="/WEB-INF/jspf/import.jspf" %>
<!doctype HTML>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
        <title> 车友会同城</title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta name="author" content="xieyongshuang_gz zhongqingbiao_gz"/>
        <link rel="stylesheet" type="text/css" href="http://js.3conline.com/wap/pcauto/2014/touch/club/club.css">
    </head>
    <body class="g-doc">
         <jsp:include page="/template/wap/common/counter.jspf">
            <jsp:param name="channel" value="7839" />
        </jsp:include>
        <%@include file="../common/intf6007.html" %>
        <!-- 公共头部 -->
        <div class="g-hd">
            <a href="http://m.pcauto.com.cn" class="header-home" title="太平洋汽车网"></a>
            <div class="header-title">
                <span class="header-title-nav">
                    <a href="${WAPROOT}/">车友会</a> 
                    &gt; <a href="${WAPROOT}/tongcheng/">同城</a>  &gt; 同城优惠
                </span>
                <a class="cur-city" href="javascript:void(0);" id="J-cur-city"></a>
            </div>
        </div>
        <div class="m-yh-list clf" id ="promotionItems">
        </div>
        <div class="g-btn-more" onclick="loadMore();" id="loadMore"><a href="javascript:void(0)">点击加载更多同城优惠 </a> </div>
        <div id="Jfoot" class="g-footer">
            <!-- 公共底部 -->
            <%@include file="../common/intf5987.html" %>
        </div>
        <script type="text/javascript" src="http://js.3conline.com/wap/common/Location-min.js"></script>
        <script type="text/javascript" src="http://js.3conline.com/wap/2013/common/js/zepto1.1.min.js" ></script>
        <script type="text/javascript">
            // 初始化定位
            var pageNo = 1;
            var pageSize = 10;
            var proCode = '110000';  //定位失败初始值
            var cityCode = '0';
            Location.init(function(location) {
                // 操作 location
                proCode = location.proCode;
                cityCode = location.cityCode;
            
                $.getJSON("${WAPROOT}/club/loadPromotion.do?req_enc=utf-8&resp_enc=utf-8&callback=?",{proCode:proCode,cityCode:cityCode,pageNo:pageNo,pageSize:pageSize},load);
                $("#J-cur-city").html(location.city);
              
            });
		  
            var loadFlag = true;
            function load(data){
                if(loadFlag){
                    if(data.data.length){
                        if(data.code==0){
                            var result = data.data;
                            for(var i=0;i<result.length;i++){
                                var promotion = result[i];
                                var html = '<a class="m-yh-item" href="'+promotion.url+'">'+
                                    '<img src="'+promotion.logo+'" width="85" height="65">'+
                                    '<p>'+promotion.name+'</p>'+
                                    '<p id="date-'+promotion.promotionId+'" class="date" data-topicId="'+promotion.topicId+'" data-id="'+promotion.promotionId+'"></p>'+
                                    '</a>';
                                $("#promotionItems").append(html); 
                                loadDate("date-"+promotion.promotionId);   
                            }
                            if(data.pageCount>pageNo){
                                $("#loadMore").html("<a href='javascript:void(0)'>点击加载更多同城优惠 </a>");
                            }else{
                                $("#loadMore").html("没有更多数据了...");
                                $("#loadMore").removeAttr("onclick");
                                loadFlag =false;
                            }
                            pageNo++;  
            			  
                        }
                    }else{
                        $("#loadMore").html("没有更多数据了...");
                        $("#loadMore").removeAttr("onclick");
                        loadFlag =false;
                    }
                }
        	  
            }

            function loadMore(){
                $.getJSON("${WAPROOT}/club/loadPromotion.do?req_enc=utf-8&resp_enc=utf-8&callback=?",{proCode:proCode,cityCode:cityCode,pageNo:pageNo,pageSize:pageSize},load);
            }
            function loadDate(pid){
        	  
                var tid = $("#"+pid).attr('data-topicId');
                var id = $("#"+pid).attr('data-id');
                var url = "${BBSROOT}/intf/activity/read.do?tid={tid}";
                url = url.replace("{tid}", tid);
                if(tid != '0'){
                    $.ajax({
                        type:"get",
                        dataType : "jsonp",
                        url:url,
                        success:function(data){
                            if(data.status==0){
                                $("#"+pid).html(data.createAtMin+" ~ "+data.createAtMax);
                            }else{
                                console.log("error "+tid+" "+data.desc);
                            }
                        },
                        error:function(){
                        }
                    });
                }
            }

        </script>

    </body>
</html>